package com.atguigu.flink.chapter02_DataStreamAPI.divide;

import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.api.java.functions.KeySelector;
import org.apache.flink.configuration.Configuration;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * Created by Smexy on 2022/10/22
 */
public class Demo11_KeyBy
{
    public static void main(String[] args) {

        Configuration configuration = new Configuration();
        configuration.setInteger("rest.port",3333);
        StreamExecutionEnvironment env = StreamExecutionEnvironment.createLocalEnvironmentWithWebUI(configuration);


        DataStreamSource<String> source = env.socketTextStream("hadoop103", 8888);

        source.keyBy(new KeySelector<String, String>()
        {
            @Override
            public String getKey(String value) throws Exception {
                return value;
            }
        })
            //.global()
              //.rescale()
              //.shuffle()
              //下游有三个线程，都能去控制台打印
              .print().setParallelism(3);

        try {
            env.execute();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
